package com.lb.comment;

// Result 类表示一个操作结果，包含状态码、消息和数据
public class Result {
    private String msg;
    private String code;
    private Object data;

    // 私有构造函数，强制使用静态工厂方法创建实例
    private Result(String msg, String code, Object data) {
        this.msg = msg;
        this.code = code;
        this.data = data;
    }

    // 静态工厂方法：成功结果
    public static Result success(String message, Object data) {
        return new Result(message, "200", data);
    }

    public static Result success(Object data) {
        return success("操作成功", data);
    }

    public static Result success() {
        return success("操作成功", null);
    }

    // 静态工厂方法：失败结果
    public static Result failure(String message, String code) {
        return new Result(message, code, null);
    }

    public static Result failure(String message) {
        return failure(message, "500");
    }

    // Getter 方法
    public String getMsg() {
        return msg;
    }

    public String getCode() {
        return code;
    }

    public Object getData() {
        return data;
    }

    // 可选：重写 toString 方法便于调试
    @Override
    public String toString() {
        return "Result{" +
                "msg='" + msg + '\'' +
                ", code='" + code + '\'' +
                ", data=" + data +
                '}';
    }
}
